import { Component, OnInit } from '@angular/core';
import { Singlepage } from '../../model/singlepage';
import { Router, ActivatedRoute } from '@angular/router';
import { HttpClient } from '@angular/common/http';
import { SinglepageService } from '../../service/singlepage.service';

@Component({
  selector: 'app-detailpage',
  templateUrl: './detailpage.component.html',
  styleUrls: ['./detailpage.component.css']
})
export class DetailpageComponent implements OnInit {
  sl:Array<Singlepage>;
  constructor(
    private http:HttpClient,
    private routerinfo:ActivatedRoute,
    private router:Router,
    private singlepageservice:SinglepageService
  ) {
    this.sl=new Array();
   }

  ngOnInit() {
    this.loadSinglepageList();
  }

  private loadSinglepageList(){
    this.sl=new Array();
    this.singlepageservice.getSinglepageList().then((data:any)=>{
    this.sl=data;
    })
  }

  addSinglepage(){
    this.router.navigate(['editpage','add']);
  }

  updateSinglepage(id:string){
    this.router.navigate(['editpage',id]);
  }

  deleteSinglepage(id:string){
    this.singlepageservice.deleteSinglepage(id)
    .then((flag:boolean)=>{
     if(flag==true){
  this.loadSinglepageList();
     }
     else{
      alert("删除异常，请刷新后重试");
     }
    })
  }

}
